package com.yulong.web.utils;

import org.springframework.util.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CooikeUtil {


    public static  void set(HttpServletResponse response,String name,String value,int maxAge){
        Cookie cookie = new Cookie(name, value);
        cookie.setPath("/");
        cookie.setMaxAge(maxAge);
        response.addCookie(cookie);
    }


    public static  String get(HttpServletRequest request, String name){
        Cookie[] cookies = request.getCookies();
        String value = null ;
        if(cookies==null){
            return null;
        }
        for(Cookie item : cookies){
                if(item.getName()!=null && name.equals(item.getName())){
                    value =  item.getValue();
                }


        }
        return value ;
    }
}
